//
//  WineshopViewController.m
//  Traveling
//
//  Created by 郑文青 on 16/7/14.
//  Copyright © 2016年 zhengwenqing’s mac. All rights reserved.
//

#import "WineshopViewController.h"

@interface WineshopViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@property (nonatomic, weak) UIActivityIndicatorView * activityView;



@end

@implementation WineshopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView.scalesPageToFit = YES;
    self.webView.dataDetectorTypes =  UIDataDetectorTypeAll;
    
    //解决网址中带有中文字符
    NSCharacterSet *set = [NSCharacterSet URLQueryAllowedCharacterSet];
    NSString *encodedString = [self.backURLStr stringByAddingPercentEncodingWithAllowedCharacters:set];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:encodedString]];
    [self.webView loadRequest:request];
    
    //activityView
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityView.center = CGPointMake(self.view.center.x, self.view.center.y - 120);
    [activityView startAnimating];
    self.activityView = activityView;
    [self.view addSubview:activityView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView{
    self.activityView.hidden = NO;
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    

    return YES;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView{
    self.activityView.hidden = YES;
    //显示网页标题
    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    self.activityView.hidden = YES;
}


@end
